package edu.sctu.zcy.month201506.day20150614.iotest;

import java.io.*;

/**
 * Created by user24 on 2015/6/14.
 */
public class ReaderTest {


    FileReader fileReader;
    FileWriter fileWriter ;
    byte[] bytes;
    public void reader(){

        int c ;
        int b = 0;
        int d;
        int e1= 0;

        char[] a = new char[5];
        File file = new File("D:\\ZCY2\\zcy1.txt");

        try {
             fileReader = new FileReader(file);
           fileWriter = new FileWriter("D:\\ZCY2\\zcy2.txt");
            while ((c = fileReader.read(a)) != -1){

                String s = String.valueOf(a);//将字符转换为字符串
                System.out.println(s);
                bytes = s.getBytes();//将字符串转换为字节数组
                fileWriter.write(a,0,c);
            }

            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
            while ((d = byteArrayInputStream.read()) != -1){
                e1 += d;
            }
            System.out.println(e1);


//            for(byte b1 : bytes){
//
//               b += b1;
//            }
//            System.out.println(b);//输出字节数

            try {
                fileReader.close();
                fileWriter.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
